package com.lb.shopguide.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.lb.baselib.base.DialogBase;
import com.lb.shopguide.R;

public class DialogZoneToast extends DialogBase {
    private TextView tvContent;

    public static DialogZoneToast getDialogZoneToast() {
        return new DialogZoneToast();
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View mFragmentView = inflater.inflate(R.layout.dialog_zone_toast, container, false);
        initData();
        initView(mFragmentView);

        return mFragmentView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        }
    }

    private void initData() {

    }

    private void initView(View view) {
        tvContent = view.findViewById(R.id.tv_content);
        tvContent.postDelayed(new Runnable() {
            @Override
            public void run() {
                DialogZoneToast.this.dismissAllowingStateLoss();
            }
        }, 3000);
    }
}
